package com.vol.controller.sys;

import com.vol.AuthParams;
import com.vol.entity.Result;
import com.vol.entity.SysDepartment;
import com.vol.entity.SysUser;
import com.vol.entity.UserInfo;
import com.vol.entity.pager.PageParams;
import com.vol.entity.pager.ResultPager;
import com.vol.requestparams.UpdateSubmitParams;
import com.vol.sys.UserService;
import com.vol.utils.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

@RestController
@RequestMapping("api/Sys_User")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserContext userContext;

    @AuthParams("/Sys_User:Search")
    @PostMapping("getPageData")
    public ResultPager<SysUser> getPageData(@RequestBody PageParams pageParams) {
        ResultPager<SysUser> result = userService.getPageData(pageParams);
        return result;
    }

    @PostMapping("Add")
    public Result Add(@RequestBody UpdateSubmitParams<SysUser> params) {
        SysUser sysUser = params.mainData;
        userService.saveOrUpdate(sysUser);
        return Result.ok(sysUser, 311, "数据添加成功！该用户初始密码为：123456");
    }

    @PostMapping("update")
    public Result update(@RequestBody UpdateSubmitParams<SysUser> params) {
        SysUser sysUser = params.mainData;
        userService.saveOrUpdate(sysUser);
        return Result.ok(sysUser, 311, "数据修改成功！");
    }

    @PostMapping("del")
    public Result del(@RequestBody ArrayList<String> ids){
        userService.del(ids);
        return Result.ok(null,317,"数据删除成功!");
    }


}
